import React from 'react';
import { createForm } from 'rc-form';
import { Button, InputItem, WingBlank, WhiteSpace,Toast,List } from 'antd-mobile';
import 'antd-mobile/dist/antd-mobile.css';
import { hashHistory} from 'react-router';

let userMsg = {};
class AnswerComfirm extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            question:'',
            answer:''
        };
    }
    componentDidMount() {
        this.props.changeTitle('忘记密码');
        this.setState({
            question: userMsg.question,
            answer: userMsg.answer
        });
    }
    componentWillMount(){
        userMsg = this.props.location.state
    }

    //忘记密码
    submit = (e) => {
        console.log(userMsg);
        let fieldValue = this.props.form.getFieldsValue(); //{answer: "11"}

        if (fieldValue.answer !== this.state.answer){
            Toast.info("答案错误，请重新输入！",1);
            return;
        }else {
            hashHistory.push({
                pathname: '/user/forgetPwd',
                state: userMsg
            })
        }
    }

    render() {
        console.log(this.state.question);
        const { getFieldProps } = this.props.form;
        const { getFieldError } = this.props.form;
        return (

            <List className="my-list">
                <InputItem
                    value={this.state.question}
                    editable={false}
                >问题</InputItem>
                <WhiteSpace/>
                <InputItem
                    {...getFieldProps('answer',
                        {
                            initialValue: '',
                        })}
                    error={!!getFieldError('answer')}
                    onErrorClick={() => {
                        Toast.fail(getFieldError('answer'), 1);
                    }}
                    type="text"
                    placeholder="请输入答案">
                    答案
                </InputItem>
                <WingBlank>
                    <WhiteSpace/>
                    <Button type="warning" size="large" onClick={this.submit}>确 定</Button><WhiteSpace/>
                </WingBlank>
            </List>
        );
    }
}

export default createForm()(AnswerComfirm);
